import { reactive, Ref, watch } from 'vue'
import { ReserveForm } from '../types'
import { toForm } from '../utils'
import { publishQuery } from '/@/views/reserve/api'

export function useReserveForm(id: Ref<string>, tenantId: Ref<string>) {
  const form = reactive(new ReserveForm())
  watch(
    id,
    async (id) => {
      if (!id) {
        return
      }
      const {
        data: { data },
      } = await publishQuery({ id, tenantId_equal: tenantId?.value })
      Object.assign(form, toForm(data[0]))
    },
    {
      immediate: true,
    }
  )
  return { form }
}
